﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4._1
{
    public partial class Form1 : Form
    {

        private string onclock = "滴答！";

        private string ring = "响铃！";

        private string ringTime = "";


        public Form1()
        {
            InitializeComponent();
            label3.Text = DateTime.Now.ToLongTimeString().ToString();
            label5.Text = onclock;
            for (int i = 0; i < 24; i++) {
                comboBox1.Items.Add(i);
            }
            for (int i = 0; i < 60; i++)
            {
                comboBox2.Items.Add(i);
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label3.Text = DateTime.Now.ToLongTimeString().ToString();
            if (label3.Text == ringTime)
            {
                label5.Text = ring;
            }
        }



        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string h = comboBox1.Text;
                string m = comboBox2.Text;
                if (int.Parse(h) >= 0 && int.Parse(h) < 24 && int.Parse(m) >= 0 && int.Parse(m) < 60)
                {
                    ringTime = h + ":" + (int.Parse(m) < 10 ? (0 + m) : m) + ":00";
                    comboBox1.Text = "时";
                    comboBox2.Text = "分";
                    label6.Text = ringTime;
                    return;
                }
            }catch(Exception)
            {
                comboBox1.Text = "时";
                comboBox2.Text = "分";
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(label5.Text == ring)
            {
                label5.Text = onclock;
            }
        }
    }
}
